﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

namespace PSTS.UI.ViewModels
{
    public class ResultPageViewModel:DependencyObject
    {

        public ResultPageViewModel(TestPassingPageViewModel testPassingPageViewModel)
        {
            Results = new List<Result>();
            int corAnswNumb = 0;
            for (int i = 0; i < testPassingPageViewModel.QuestionPagesList.Count; i++)
            {
                var x = new Result
                {
                    Number = testPassingPageViewModel.QuestionNumbers[i],
                    Res = testPassingPageViewModel.QuestionPagesList[i].Answer() ==
                          testPassingPageViewModel.QuestionsList[i].CorrectAnsIndex
                        ? "+"
                        : "-",
                    Question = testPassingPageViewModel.QuestionPagesList[i]
                };
                Results.Add(x);
                if (x.Res == "+")
                    corAnswNumb++;
            }
            Mark = corAnswNumb.ToString() + "/" + Results.Count.ToString();
        }

        #region properties

        public List<Result> Results
        {
            get { return (List<Result>)GetValue(ResultsProperty); }
            set { SetValue(ResultsProperty, value); }
        }
        public static readonly DependencyProperty ResultsProperty = DependencyProperty.Register(
                                                                        "Results",
                                                                        typeof(List<Result>),
                                                                        typeof(ResultPageViewModel),
                                                                        new PropertyMetadata(null));
        public Page QuestionFrameContent
        {
            get { return (Page)this.GetValue(QuestionFrameContentProperty); }
            set { this.SetValue(QuestionFrameContentProperty, value); }
        }
        public static readonly DependencyProperty QuestionFrameContentProperty = DependencyProperty.Register(
          "QuestionFrameContent",
          typeof(Page),
          typeof(ResultPageViewModel),
          new PropertyMetadata(null));

        public Result SelectedResult
        {
            get { return (Result)GetValue(SelectedResultProperty); }
            set { SetValue(SelectedResultProperty, value); }
        }
        public static readonly DependencyProperty SelectedResultProperty = DependencyProperty.Register(
                                                                        "SelectedResult",
                                                                        typeof(Result),
                                                                        typeof(ResultPageViewModel),
                                                                        new PropertyMetadata(SelectedResult_ChangedCallback));

        public string Mark
        {
            get { return (string)GetValue(MarkProperty); }
            set { SetValue(MarkProperty, value); }
        }
        public static readonly DependencyProperty MarkProperty = DependencyProperty.Register(
                                                                        "Mark",
                                                                        typeof(string),
                                                                        typeof(ResultPageViewModel),
                                                                        new PropertyMetadata("0/0"));

        private static void SelectedResult_ChangedCallback(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            //var viewModel = sender as ResultPageViewModel;
            //if (viewModel != null)
            //{
            //    viewModel.QuestionFrameContent = 
            //}
        }

        #endregion
    }
}
